﻿using System.Collections.Generic;

namespace DataScripter.Scripting.Output
{
    internal class VariableContext : IVariableContext
    {
        private readonly IDictionary<string, string> _variables = new Dictionary<string, string>();

        public bool HasVariableName(string columnName, object rawValue)
        {
            string variableName = columnName + rawValue;
            return _variables.ContainsKey(variableName);
        }

        public string RequestVariableName(string columnName, object rawValue, bool variableAlreadyDeclared)
        {
            string variableName = columnName + rawValue;
            if (variableAlreadyDeclared)
            {
                return variableName;
            }
            while (_variables.ContainsKey(variableName))
            {
                variableName = variableName + "_1";
            }
            _variables.Add(variableName, variableName);
            return variableName;
        }
    }
}